//
//  MeTableViewCell.m
//  明和智能
//
//  Created by 李李善 on 2018/8/23.
//  Copyright © 2018年 inno. All rights reserved.
//

#import "MeTableViewCell.h"

@implementation MeTableViewCell
-(void)onAsInitAddView:(UIView *)view forViewController:(UIViewController *)ViewController forDataSource:(id)dataSource AtIndexPath:(NSIndexPath *)indexPath
{
    self.backgroundColor = hexCOLOR(@"F4E0C6");
    UILabel *label = ({
        UILabel *l  = [UILabel new];
        l.text = @"会员";
        l.font = kSysFont(kFitW(12));
        l.textColor = hexCOLOR(@"C8731D");
        l.backgroundColor = hexCOLOR(@"FDCA42");
        l.textAlignment = NSTextAlignmentCenter;
        l.cornerRadius =kFitH(25)/2;
        [l masksToBounds];
        [view addV:l];
        l;
    });
    
    UILabel *label1 = ({
        UILabel *l  = [UILabel new];
        l.text = @"您的月卡还剩7天";
        l.font = kSysFont(kFitW(12));
        l.textColor = [UIColor blackColor];
        [view addV:l];
        l;
    });
    
    UIButton *v1 = ({
        UIButton *l = [UIButton buttonWithType:UIButtonTypeCustom];
        [l setNormalTitle:@"续费"];
        [l setNormalTitleColor:[UIColor whiteColor]];
        l.titleLabel.font = kSysFont(kFitH(12));
        l.backgroundColor = hexCOLOR(@"EB8522");
        l.tag =100;
        [l AddTarget:ViewController Action:@selector(onClickButton:)];
        //        [l setNormalBackImage:IMAGE(@"")];
        [view addV:l];
        l;
    });
    
    [self onMainSetSubViewFrame:^(UIView *view, CGPoint origin, CGSize size, CGPoint center) {
        label.size = CGSizeMake(kFitW(45),kFitH(25));
        label.left = kFitW(15);
        label.centerY = size.height/2;
        
        [label1 sizeToFit];
        label1.left = label.right+kFitW(15);
        label1.centerY = size.height/2;
        
        v1.size = CGSizeMake(kFitW(75),kFitH(35));
        v1.right=size.width-kFitW(15);
        v1.centerY = size.height/2;
        v1.cornerRadius =kFitH(5);
        
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end


@implementation MeTableViewCell1

-(void)onAsInitAddView:(UIView *)view forViewController:(UIViewController *)ViewController forDataSource:(NSArray *)dataSource AtIndexPath:(NSIndexPath *)indexPath
{
    
    NSMutableArray *arr = [NSMutableArray array];
    int m=2;
    for (NSDictionary *dic in dataSource) {
        NSString *imageName = dic[@"image"];
        NSString *title = dic[@"title"];
        if ([dic[@"hidden"] integerValue]==1) {
            MeButton *button = [MeButton buttonWithType:UIButtonTypeCustom];
            [button setNormalImage:[UIImage imageNamed:imageName]];
            [button setNormalTitle:title];
            [button setNormalTitleColor:[UIColor blackColor]];
            button.titleLabel.font = kSysFont(kFitW(13));
            button.tag =100*m;
            [button AddTarget:ViewController Action:@selector(onClickButton:)];
            [view addV:button];
            [arr addObject:button];
        }else
        {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setNormalImage:[UIImage imageNamed:imageName]];
            [button setNormalTitle:title];
            [button setNormalTitleColor:[UIColor blackColor]];
            button.titleLabel.font = kSysFont(kFitW(13));
            button.tag =100*m;
            [button AddTarget:ViewController Action:@selector(onClickButton:)];
            [view addV:button];
            [arr addObject:button];
        }
    
        m++;
    }
    
    [self onMainSetSubViewFrame:^(UIView *view, CGPoint origin, CGSize size, CGPoint center) {
        CGFloat w= size.width/arr.count;
        int i = 0;
        for (UIButton *btn in arr) {
            btn.top = 0;
            btn.size = CGSizeMake(w,size.height);
            btn.left = w*i;
            [btn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleTop imageTitleSpace:5];
            i++;
        }
    }];
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end


@implementation MeTableViewCell2

-(void)onAsInitAddView:(UIView *)view forViewController:(UIViewController *)ViewController forDataSource:(id)dataSource AtIndexPath:(NSIndexPath *)indexPath
{
    self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    self.textLabel.font = kSysFont(kFitW(12));
    
}
-(void)update:(NSDictionary *)model forTableView:(UITableView *)tableView AtIndexPath:(NSIndexPath *)indexPath
{
    self.textLabel.text = model[@"title"];
    self.imageView.image = [UIImage imageNamed:model[@"image"]];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end



@implementation MeTableHeaderFooterView

-(void)onAsInitAddView:(UIView *)view forViewController:(UIViewController *)ViewController forDataSource:(id)dataSource AtSection:(NSInteger)section
{
    
    self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"wode_bg_img"]];
    UIImageView *imageV = ({
        UIImageView *l  = [UIImageView new];
        l.backgroundColor = [UIColor redColor];
        [l addTarget:ViewController action:@selector(onIconClick:)];
        [view addV:l];
        l;
    });
    
    UILabel *phone = ({
        UILabel *l  = [UILabel new];
        l.text = @"195****6996";
        l.font = kSysFont(kFitW(13));
        l.textColor = [UIColor whiteColor];
        [view addV:l];
        l;
    });
    
    UILabel *name = ({
        UILabel *l  = [UILabel new];
        l.text = @"粤A231231";
        l.font = kSysFont(kFitW(12));
        l.textColor = [UIColor whiteColor];
        [view addV:l];
        l;
    });
    
    
    
    [self onMainSetSubViewFrame:^(UIView *view, CGPoint origin, CGSize size, CGPoint center) {
        imageV.size = CGSizeMake(kFitW(80), kFitW(80));
        imageV.top = kFitH(15);
        imageV.centerX = size.width/2;
        
        [phone sizeToFit];
        phone.centerX = size.width/2;
        phone.top =imageV.bottom+kFitH(10);
        
        [name sizeToFit];
        name.centerX = size.width/2;
        name.top =phone.bottom+kFitH(10);
    }];
    
}
@end

@implementation MeButton
+(instancetype)buttonWithType:(UIButtonType)buttonType
{
    MeButton *button = [super buttonWithType:buttonType];
    
    UIView *lin = ({
        UIView *l  = [UIView new];
        l.backgroundColor = hexCOLOR(@"D5D5D5");
        [button addV:l];
        l;
    });
    
    UIView *lin1 = ({
        UIView *l  = [UIView new];
        l.backgroundColor = hexCOLOR(@"D5D5D5");
        [button addV:l];
        l;
    });
    
    [button onMainSetSubViewFrame:^(UIView *view, CGPoint origin, CGSize size, CGPoint center) {
        lin.size = CGSizeMake(0.5,size.height-kFitH(30));
        lin.centerY = size.height/2;
        lin.left = 0;
        
        lin1.size = CGSizeMake(0.5,size.height-kFitH(30));
        lin1.centerY = size.height/2;
        lin1.right = size.width;
    }];
    
    return button;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    CGPoint origin = self.frame.origin;
    CGSize size = self.frame.size;
    self.layoutBlock(self, origin, size,self.center);
}
@end
